import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/bean/bean_penting.dart';
import 'package:flutter_learn_vi/src/net/dio_utils.dart';
import 'package:flutter_learn_vi/src/utils/navigator_utils.dart';
import 'package:flutter_learn_vi/src/utils/toast_utils.dart';

import 'PendingListItemWidget.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2020/12/11.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单
class PendindReviewPage extends StatefulWidget {
  final PentingBean pentingBean;

  PendindReviewPage({@required this.pentingBean});

  @override
  _PendindReviewPageState createState() => _PendindReviewPageState();
}

class _PendindReviewPageState extends State<PendindReviewPage> {
  TextEditingController _editingController = TextEditingController();

  FocusNode _focusNode = FocusNode();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("我要回复"),
      ),

      ///填充布局
      body: Container(
          color: Colors.white,
          width: double.infinity,
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                PendingListItemWidget(
                  pentingBean: widget.pentingBean,
                  isShowCreateTime: true,
                  isShowBottomCount: false,
                ),
                Container(
                  padding: EdgeInsets.all(12),
                  child: TextField(
                    controller: _editingController,
                    maxLength: 100,
                    maxLines: 8,
                    focusNode: _focusNode,
                    style: TextStyle(),
                    decoration: InputDecoration(
                        hintText: "请输入您想要回复内容", border: OutlineInputBorder()),
                  ),
                ),
                Align(
                  child: Container(
                    width: 100,
                    margin: EdgeInsets.only(right: 12),
                    child: ElevatedButton(
                      onPressed: () {
                        String text = _editingController.text;
                        if (text.length == 0) {
                          ToastUtils.showToast("请输入您的反馈内容");
                          return;
                        }
                        addPend(text);
                      },
                      child: Text("提交"),
                    ),
                  ),
                  alignment: Alignment.centerRight,
                ),
                Container(
                  padding: EdgeInsets.all(12),
                  child: Text(
                    "注意:请发布规范的内容，不可发布局色情、欺诈、广告等内容，新发布的内容管理员审核通过后方可被其他人看到",
                    style: TextStyle(color: Colors.redAccent),
                  ),
                ),
              ],
            ),
          )),
    );
  }

  Future<bool> addPend(String text) async {
    _focusNode.unfocus();
    Map<String, dynamic> map = {
      "comment": text,
      "tpye": 3,
      "pId": widget.pentingBean.id,
    };
    ResponseInfo partResponseInfo = await DioUtils.instance.postRequest(
      url: HttpHelper.pending_helper_add,
      jsonMap: map,
    );
    if (partResponseInfo.success) {
      LogUtil.e("添加成功");
      ToastUtils.showToast("添加成功 请等待管理员审核");
      NavigatorUtils.pop(context, parameters: true);
    } else {
      LogUtil.e("添加失败");
      ToastUtils.showToast("添加失败${partResponseInfo.message}");
    }

    return Future.value(true);
  }
}
